<template>
    <div class="home-view">
        <el-row :gutter="20" class="stats-row">
            <el-col :xs="24" :sm="12" :md="6">
                <el-card class="stat-card" shadow="hover">
                    <div class="stat-content">
                        <div class="stat-icon students">
                            <el-icon :size="40"><UserFilled /></el-icon>
                        </div>
                        <div class="stat-info">
                            <div class="stat-number">1,234</div>
                            <div class="stat-label">在校学生</div>
                        </div>
                    </div>
                </el-card>
            </el-col>

            <el-col :xs="24" :sm="12" :md="6">
                <el-card class="stat-card" shadow="hover">
                    <div class="stat-content">
                        <div class="stat-icon dormitory">
                            <el-icon :size="40"><OfficeBuilding /></el-icon>
                        </div>
                        <div class="stat-info">
                            <div class="stat-number">56</div>
                            <div class="stat-label">宿舍总数</div>
                        </div>
                    </div>
                </el-card>
            </el-col>

            <el-col :xs="24" :sm="12" :md="6">
                <el-card class="stat-card" shadow="hover">
                    <div class="stat-content">
                        <div class="stat-icon building">
                            <el-icon :size="40"><School /></el-icon>
                        </div>
                        <div class="stat-info">
                            <div class="stat-number">8</div>
                            <div class="stat-label">宿舍楼栋</div>
                        </div>
                    </div>
                </el-card>
            </el-col>

            <el-col :xs="24" :sm="12" :md="6">
                <el-card class="stat-card" shadow="hover">
                    <div class="stat-content">
                        <div class="stat-icon rate">
                            <el-icon :size="40"><TrendCharts /></el-icon>
                        </div>
                        <div class="stat-info">
                            <div class="stat-number">95%</div>
                            <div class="stat-label">入住率</div>
                        </div>
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <el-row :gutter="20" class="content-row">
            <el-col :xs="24" :md="16">
                <el-card class="chart-card" shadow="hover">
                    <template #header>
                        <div class="card-header">
                            <span class="title">入住趋势</span>
                            <el-button text>查看详情</el-button>
                        </div>
                    </template>
                    <div class="chart-placeholder">
                        <el-icon :size="60" color="#ccc"><TrendCharts /></el-icon>
                        <p>图表区域</p>
                    </div>
                </el-card>
            </el-col>

            <el-col :xs="24" :md="8">
                <el-card class="notice-card" shadow="hover">
                    <template #header>
                        <div class="card-header">
                            <span class="title">最新公告</span>
                            <el-button text>更多</el-button>
                        </div>
                    </template>
                    <el-timeline>
                        <el-timeline-item
                            v-for="(item, index) in notices"
                            :key="index"
                            :timestamp="item.time"
                            placement="top"
                        >
                            <div class="notice-item">{{ item.content }}</div>
                        </el-timeline-item>
                    </el-timeline>
                </el-card>
            </el-col>
        </el-row>

        <el-row :gutter="20">
            <el-col :xs="24">
                <el-card class="table-card" shadow="hover">
                    <template #header>
                        <div class="card-header">
                            <span class="title">最近登记</span>
                            <el-button text>查看全部</el-button>
                        </div>
                    </template>
                    <el-table :data="recentData" style="width: 100%">
                        <el-table-column prop="name" label="学生姓名" width="120" />
                        <el-table-column prop="studentId" label="学号" width="150" />
                        <el-table-column prop="dormitory" label="宿舍" width="120" />
                        <el-table-column prop="building" label="楼栋" width="120" />
                        <el-table-column prop="time" label="登记时间" />
                        <el-table-column label="状态" width="100">
                            <template #default="scope">
                                <el-tag :type="scope.row.status === '已入住' ? 'success' : 'warning'">
                                    {{ scope.row.status }}
                                </el-tag>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { UserFilled, OfficeBuilding, School, TrendCharts } from '@element-plus/icons-vue'

const notices = ref([
    { time: '2025-10-14 10:30', content: '宿舍卫生检查通知' },
    { time: '2025-10-13 15:20', content: '新生宿舍分配完成' },
    { time: '2025-10-12 09:00', content: '宿舍管理系统升级维护' },
    { time: '2025-10-11 14:00', content: '本月水电费用统计' }
])

const recentData = ref([
    {
        name: '张三',
        studentId: '2023001',
        dormitory: '101',
        building: 'A栋',
        time: '2025-10-14 09:30',
        status: '已入住'
    },
    {
        name: '李四',
        studentId: '2023002',
        dormitory: '102',
        building: 'A栋',
        time: '2025-10-14 10:15',
        status: '已入住'
    },
    {
        name: '王五',
        studentId: '2023003',
        dormitory: '201',
        building: 'B栋',
        time: '2025-10-14 11:00',
        status: '待入住'
    },
    {
        name: '赵六',
        studentId: '2023004',
        dormitory: '202',
        building: 'B栋',
        time: '2025-10-14 14:20',
        status: '已入住'
    }
])
</script>

<style lang="scss" scoped>
.home-view {
    .stats-row {
        margin-bottom: 20px;

        .stat-card {
            margin-bottom: 20px;

            :deep(.el-card__body) {
                padding: 20px;
            }

            .stat-content {
                display: flex;
                align-items: center;
                gap: 20px;

                .stat-icon {
                    width: 70px;
                    height: 70px;
                    border-radius: 12px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: #fff;

                    &.students {
                        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                    }

                    &.dormitory {
                        background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
                    }

                    &.building {
                        background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
                    }

                    &.rate {
                        background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
                    }
                }

                .stat-info {
                    flex: 1;

                    .stat-number {
                        font-size: 28px;
                        font-weight: 600;
                        color: #333;
                        margin-bottom: 5px;
                    }

                    .stat-label {
                        font-size: 14px;
                        color: #666;
                    }
                }
            }

            &:hover {
                transform: translateY(-5px);
                transition: all 0.3s;
            }
        }
    }

    .content-row {
        margin-bottom: 20px;

        .chart-card,
        .notice-card {
            margin-bottom: 20px;

            .chart-placeholder {
                height: 300px;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                color: #999;
            }

            .notice-item {
                cursor: pointer;
                color: #666;

                &:hover {
                    color: #409EFF;
                }
            }
        }
    }

    .table-card {
        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .title {
                font-size: 16px;
                font-weight: 600;
                color: #333;
            }
        }
    }
}
</style>
